//
//  SDGroupCell.m
//  SDNestedTablesExample
//
//  Created by Daniele De Matteis on 21/05/2012.
//  Copyright (c) 2012 Daniele De Matteis. All rights reserved.
//

#import "SDGroupCell2.h"
#import <QuartzCore/QuartzCore.h>
#import "SDNestedTableViewController2.h"
#import "clsOtherFun.h"
#import "clsFileFun.h"

@implementation SDGroupCell2


@synthesize parentTable;
@synthesize subTable;

@synthesize isExpanded;
@synthesize subCellsAmt;
@synthesize cellIndex;

@synthesize selectedIconImage;
@synthesize unSelectedIconImage;


+ (int) getHeight
{
    return height2;
}

+ (int) getsubCellHeight
{
    return subCellHeight3;
}

- (void)FillData:(NSDictionary *)pcls
{
    self.ExpressID.text = [pcls objectForKey:@"ExpressNumber"];
    if ([[pcls objectForKey:@"ExpressID"]isKindOfClass:[NSString class]]) {
        self.ExpressNumber.text = [pcls objectForKey:@"ExpressID"];
    }
    
    self.CreateDatetime.text = [pcls objectForKey:@"CreateDatetime"];
}


#pragma mark - Table view
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return subCellsAmt;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SDSubCell2 *cell = [tableView dequeueReusableCellWithIdentifier:@"SubCell2"];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"SDSubCell2" owner:self options:nil] lastObject];
        cell.parentViewController = parentTable;
    }
    
    cell = [self.parentTable item:self setSubItem:cell forRowAtIndexPath:indexPath];
    
//    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
//    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return subCellHeight3;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	[tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    SDSubCell2 *cell = (SDSubCell2 *)[tableView cellForRowAtIndexPath:indexPath];
    if (cell == nil)
    {
        cell = (SDSubCell2 *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
    }
    
    cell.cellIndex = indexPath.row;
    [self.parentTable groupCell:self didSelectSubCell:cell withIndexPath:indexPath andWithTap:YES];
}

@end
